package com.kabigon.tiny.controller;

import com.kabigon.tiny.domian.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.tiny.controller
 * @data 2022/10/16 14:01
 */
@RestController
@RequestMapping("/books")
public class BookController {

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Book get(@PathVariable("id") String id) {
        Book book = new Book();
        book.setName("育碧");
        book.setPrice(12.1);
        System.out.println("查询成功！");
        return book;
    }

    @GetMapping()
    public List<Book> getAll() {
        Book book = new Book();
        book.setName("育碧");
        book.setPrice(12.1);
        System.out.println("查询成功全部！");
        List<Book> books = new ArrayList<>(1);
        books.add(book);
        return books;
    }

    /**
     * 保存
     * @param book
     * @return
     */
    @PostMapping
    public Book save(@RequestBody Book book) {
        System.out.println("保存成功！");
        return book;
    }

    @PutMapping
    public Book modify(@RequestBody Book book) {
        System.out.println("修改成功！");
        return book;
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Integer id) {
        System.out.println("删除成功！");
    }


}
